package br.unifor.cct.mia.xover;

import br.unifor.cct.mia.evolutionary.Genotype;
import br.unifor.cct.mia.ga.Ga;
import br.unifor.cct.mia.util.Methods;

public class XOverOriginal extends XOver {

	private void xover(Ga Ga) {
        if (Ga.configurations.getNvars() > 1) {
            int point = (Ga.configurations.getNvars() == 2?1:Methods.randIntValue(1, Ga.configurations.getNvars()));
            double aux[] = new double[point];
            System.arraycopy(((Genotype)Ga.population[one]).getGene(), 0, aux, 0, point-1);
            System.arraycopy(((Genotype)Ga.population[two]).getGene(), 0, ((Genotype)Ga.population[one]).getGene(), 0, point-1);
            System.arraycopy(aux, 0, ((Genotype)Ga.population[two]).getGene(), 0, point-1);
        }
	}
	
	public Object execute(Object value) {
    	Object[] o = (Object[])value;
		Ga Ga = (Ga)o[0];
		
		xover(Ga);
		return Ga.population;
	}
}